package com.chis.jmx;

import com.chis.jm.pojo.zabbix.TjMntlog;
import com.chis.jmlogmccity.receive.LogCityMBean;

import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.util.Date;
import java.util.List;

/**
 * 
 * @Description 
 * @Company zwx
 * @author wlj
 * @version 2019年06月26日
 */
public class JmxInfo {

    public static void main(String[] args) {
        try {
            String jmxaddr = args[0];
            String objname = args[1];
            //JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://103.229.215.240:60117/jndi/rmi://103.229.215.240:60116/jmxrmiLog");;
            JMXServiceURL url = new JMXServiceURL(jmxaddr);;
            JMXConnector jmxc = JMXConnectorFactory.connect(url, null);;
            MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
            ObjectName mbeanName = new ObjectName("com.chis.jm:name="+objname);
            LogCityMBean logBean = MBeanServerInvocationHandler.newProxyInstance(mbsc, mbeanName, LogCityMBean.class, false);
            List<String[]> list = logBean.getList();
            if (list != null && list.size() > 0) {
                for (String[] s : list) {
                    System.out.println("儿童编码："+s[0]);
                    System.out.println("采集内容："+s[1]);
                    System.out.println("=================");
                }
                //logBean.clearList();
            }
            jmxc.close();

        } catch (Exception e){
            e.printStackTrace();
        }

    }
}
